﻿#ifndef TRANSCODE_H
#define TRANSCODE_H
#include "getopt.h"
struct AVFormatContext;
struct AVFilterGraph;
struct AVFilterContext;
struct AVPacket;
struct AVFrame;
struct AVCodecContext;

typedef struct FilteringContext {
    AVFilterContext* buffersink_ctx;
    AVFilterContext* buffersrc_ctx;
    AVFilterGraph* filter_graph;
    AVPacket* enc_pkt;
    AVFrame* filtered_frame;
} FilteringContext;

typedef struct StreamContext {
    AVCodecContext* dec_ctx;//解码
    AVCodecContext* enc_ctx;//编码
    AVFrame* dec_frame;//解码后的数据
} StreamContext;

typedef struct Cmd_Parameters {
    char input_file[50];
    char output_file[50];
    unsigned int vcodec = 0;//输出视频编码器id
    int video_height = 0;//输出H
    int video_width = 0;//输出W
    int video_frame_rate = 0;//输出帧率
    bool video_only = false;//是否只保留视频流
} Commondpara;



class Transcode{
public:
    AVFormatContext* ifmt_ctx;//输入
    AVFormatContext* ofmt_ctx;//输出
    FilteringContext* filter_ctx;//滤镜
    int v_stream_index = -1;
    StreamContext* stream_ctx;
    Commondpara parameters;
public:
    int open_input_file(const char* filename);
    int open_output_file(const char* filename);
    int init_filter(FilteringContext* fctx, AVCodecContext* dec_ctx,
                    AVCodecContext* enc_ctx, const char* filter_spec);
    int init_filters(void);
    int encode_write_frame(unsigned int stream_index, int flush);
    int filter_encode_write_frame(AVFrame* frame, unsigned int stream_index);
    int flush_encoder(unsigned int stream_index);
    void clear_up();
};

#endif // TRANSCODE_H
